package com.springcloud.sc.ucpv5.util;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 同一线程池处理
 * 
 * @author Administrator
 * 
 */
public class ThreadUtil {
	// 线程池
	private ExecutorService executor_instance;

	private static ThreadUtil instance = null;

	public static ThreadUtil getInstance() {
		if (instance == null) {
			instance = new ThreadUtil();
		} else {
			if (instance.executor_instance.isShutdown()) {
				instance.executor_instance = Executors.newCachedThreadPool();
			}
		}
		return instance;
	}

	public ThreadUtil() {
		executor_instance = Executors.newCachedThreadPool();
	}

	public void Call(Callable<Object> call) {
		executor_instance.submit(call);
	}

	// // 目的是为了将节点下面的所有的子节点都加载进来,启动完毕时做一次该操作
	// public void 加载子节点的节点数据(MyNode stub) {
	// final List<MyNode> nodeList = stub.getListModel().getNodeList();
	// //System.out.println("待查下級節點數目:" + stub.getIdlData().NodeName + "" +
	// nodeList.size());
	// try {
	// executor_instance.submit(new Callable<Object>() {
	// public Object call() throws Exception {
	// try {
	// for(MyNode node : nodeList){
	// // String PhysicsNodeNumber = node.getPhysicsNodeNumber();
	// // String LogicNodeNumber = node.getLogic_NodeNumber();
	// //
	// // SecuResult retResult = new SecuResult();
	// // NodeQueryRspHolder nodeRsp = new NodeQueryRspHolder();
	// // SecuResult tmpresult =
	// MessageService.getInstance().getIDXCmdInterface().queryNodeList(PhysicsNodeNumber,LogicNodeNumber,
	// nodeRsp, false,false);
	// // retResult.uniteResult(tmpresult);
	// // node.getListModel().pushData(nodeRsp.value);
	// node.loadData();
	// 加载子节点的节点数据(node);
	// MessageService.getInstance().getIDXCmdInterface().queryGroupStatus_TongJi(node.getPhysicsNodeNumber(),node.getLogic_NodeNumber());
	// Thread.sleep(50);
	// }
	// } catch (Throwable e) {
	// e.printStackTrace();
	// return null;
	// }
	// return null;
	// }
	// });
	// } catch (Throwable e) {
	// e.printStackTrace();
	// }
	// }
}
